package com.titleevaluation.controller;

import com.titleevaluation.entity.WorkSummary;
import com.titleevaluation.service.WorkSummaryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("/api/applications/{applicationId}/work-summary")
public class WorkSummaryController {

    private final WorkSummaryService workSummaryService;

    public WorkSummaryController(WorkSummaryService workSummaryService) {
        this.workSummaryService = workSummaryService;
    }

    @PostMapping
    public ResponseEntity<WorkSummary> createOrUpdateWorkSummary(@PathVariable Long applicationId, @RequestBody WorkSummary workSummary) {
        WorkSummary savedWorkSummary = workSummaryService.createOrUpdateWorkSummary(applicationId, workSummary);
        return ResponseEntity.ok(savedWorkSummary);
    }

    @GetMapping
    public ResponseEntity<WorkSummary> getWorkSummaryByApplicationId(@PathVariable Long applicationId) {
        Optional<WorkSummary> workSummary = workSummaryService.getWorkSummaryByApplicationId(applicationId);
        return workSummary.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
    }
}

